#include "tablestruct.h"

CTableStruct::CTableStruct()
{
    m_uOp = 0;
    m_uSave = 0;
}
CTableStruct::~CTableStruct()
{
}
HRESULT CTableStruct::AddTableRecord(const FieldSturct& field)
{
    // logi("name=>%s,type=>%s,size=>%u,index =>%u",
    //	field.name,field.type,field.size,field.index);

    rc_error(field.name[0] != 0, E_FAIL);
    rc_error(field.type[0] != 0, E_FAIL);

    m_vecTableFields.push_back(field);

    return S_OK;
}
HRESULT CTableStruct::GetTableRecord(FieldSturct* field, ULONG loop)
{
    rc_error((loop >= 0 && loop < m_vecTableFields.size()), E_FAIL);

    s_memcpy(field->name, m_vecTableFields[loop].name, LOG_FIELD_NAME_LEN);
    s_memcpy(field->type, m_vecTableFields[loop].type, LOG_FIELD_TYPE_LEN);
    field->size = m_vecTableFields[loop].size;
    field->index = m_vecTableFields[loop].index;

    return S_OK;
}
HRESULT CTableStruct::GetTableRecords(FieldSturct fields[], ULONG count)
{
    ULONG uloop = 0;
    for (uloop = 0; uloop < count; uloop++) {
        s_strcpy(fields[uloop].name, LOG_FIELD_NAME_LEN, m_vecTableFields[uloop].name);
        s_strcpy(fields[uloop].type, LOG_FIELD_TYPE_LEN, m_vecTableFields[uloop].type);
        fields[uloop].size = m_vecTableFields[uloop].size;
        fields[uloop].index = m_vecTableFields[uloop].index;
    }
    return S_OK;
}

HRESULT CTableStruct::ClearTableRecord()
{
    return S_OK;
}
HRESULT CTableStruct::GetFieldsCount(ULONG& count)
{
    count = m_vecTableFields.size();
    return S_OK;
}
HRESULT CTableStruct::SetKeyValue(LPCSTR key, LPCSTR value)
{
    if (s_stricmp(Rule_Op, key) == 0) {
    } else if (s_stricmp(Rule_Save, key) == 0) {
    }
    return S_OK;
}
HRESULT CTableStruct::GetKeyValue(LPCSTR key, LPSTR value)
{
    return S_OK;
}
UINT CTableStruct::IsExist()
{
    return m_uSave;
}
UINT CTableStruct::GetOp()
{
    return m_uOp;
}
UINT CTableStruct::GetLevel()
{
    return 0;
}
